home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / IEditor / Generators / E / data_misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  9.3 KB  |  360 lines

  1. /// Includes
  2. #define INTUI_V36_NAMES_ONLY
  3.  
  4. #include <exec/types.h>                 // exec
  5. #include <exec/lists.h>
  6. #include <exec/nodes.h>
  7. #include <dos/dos.h>                    // dos
  8. #include <dos/dostags.h>
  9. #include <intuition/intuition.h>        // intuition
  10. #include <graphics/text.h>              // graphics
  11. #include <libraries/gadtools.h>         // libraries
  12. #include <clib/exec_protos.h>           // protos
  13. #include <clib/dos_protos.h>
  14. #include <clib/intuition_protos.h>
  15. #include <pragmas/exec_pragmas.h>       // pragmas
  16. #include <pragmas/dos_pragmas.h>
  17. #include <pragmas/intuition_pragmas.h>
  18. #include <pragmas/gadtools_pragmas.h>
  19.  
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <ctype.h>
  24.  
  25. #include "DEV_IE:Generators/defs.h"
  26. #include "DEV_IE:Include/IEditor.h"
  27.  
  28. #include "Protos.h"
  29. ///
  30. /// Data
  31. static UBYTE   MenuTmp[] = "\nPROC %smenued()\n"
  32.             "\t/*  Routine for menu \"%s\"  */\n"
  33.             "\tRETURN TRUE\n"
  34.             "ENDPROC\n";
  35. ///
  36.  
  37.  
  38. /// WriteMenuStruct
  39. void WriteMenuStruct( struct GenFiles *Files, struct IE_Data *IE )
  40. {
  41.     struct MenuTitle   *title;
  42.     struct _MenuItem   *item;
  43.     struct MenuSub     *sub;
  44.     struct WindowInfo  *wnd;
  45.     struct ImageNode   *img;
  46.     UBYTE               buffer[300], lent, leni, lens, *str;
  47.     ULONG               smart;
  48.  
  49.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  50.     if( wnd->wi_NumMenus ) {
  51.         TEXT    Label[60];
  52.  
  53.         StrToLower( wnd->wi_Label, Label );
  54.  
  55.         smart = IE->C_Prefs & SMART_STR;
  56.  
  57.         if( IE->SrcFlags & LOCALIZE )
  58.         smart = wnd->wi_Tags & W_LOC_MENUS;
  59.  
  60.         FPrintf( Files->Std, "\nDEF %snewmenu = [\n", Label );
  61.  
  62.         for( title = wnd->wi_Menus.mlh_Head; title->mt_Node.ln_Succ; title = title->mt_Node.ln_Succ ) {
  63.  
  64.         FPuts( Files->Std, "\tNM_TITLE, " );
  65.  
  66.         if( title->mt_Text[0] ) {
  67.             lent = strlen( title->mt_Text );
  68.             strcpy( buffer, title->mt_Text );
  69.             strcat( buffer, "/" );
  70.  
  71.             if( smart )
  72.             FPrintf( Files->Std, "%s", (FindString( &Files->Strings, title->mt_Text ))->Label );
  73.             else
  74.             FPrintf( Files->Std, "'%s'", title->mt_Text );
  75.         } else {
  76.             FPuts( Files->Std, Null );
  77.         }
  78.  
  79.         FPuts( Files->Std, ", NIL, " );
  80.  
  81.         if( title->mt_Flags & M_DISABLED )
  82.             FPuts( Files->Std, "NM_MENUDISABLED" );
  83.         else
  84.             FPuts( Files->Std, Null );
  85.  
  86.         FPuts( Files->Std, ", 0, NIL,\n" );
  87.  
  88.         for( item = title->mt_Items.mlh_Head; item->min_Node.ln_Succ; item = item->min_Node.ln_Succ ) {
  89.  
  90.             str = item->min_Image ? "\t  IM_ITEM" : "\t  NM_ITEM";
  91.             FPuts( Files->Std, str );
  92.  
  93.             leni = strlen( item->min_Text );
  94.             strcat( buffer, item->min_Text );
  95.  
  96.             FPuts( Files->Std, ", " );
  97.  
  98.             if( item->min_Flags & M_BARLABEL ) {
  99.             FPuts( Files->Std, "NM_BARLABEL" );
  100.             } else {
  101.             if( img = item->min_Image ) {
  102.                 TEXT    Label[60];
  103.  
  104.                 (ULONG)img -= sizeof( struct Node );
  105.  
  106.                 StrToLower( img->in_Label, Label );
  107.                 FPrintf( Files->Std, "{%simg}", Label );
  108.             } else {
  109.                 if( item->min_Text[0] )
  110.                 if( smart )
  111.                     FPrintf( Files->Std, "%s", (FindString( &Files->Strings, item->min_Text ))->Label );
  112.                 else
  113.                     FPrintf( Files->Std, "'%s'", item->min_Text );
  114.                 else
  115.                 FPuts( Files->Std, Null );
  116.             }
  117.             }
  118.  
  119.             FPuts( Files->Std, ", " );
  120.  
  121.             if(!( item->min_NumSubs )) {
  122.             if( item->min_CommKey[0] ) {
  123.                 if( smart )
  124.                 FPrintf( Files->Std, "%s", (FindString( &Files->Strings, item->min_CommKey ))->Label );
  125.                 else
  126.                 FPrintf( Files->Std, "'%s'", item->min_CommKey );
  127.             } else
  128.                 FPuts( Files->Std, Null );
  129.             } else {
  130.             FPuts( Files->Std, Null );
  131.             }
  132.  
  133.             FPrintf( Files->Std, ", $%lx, %ld, ", item->min_Flags, item->min_MutualExclude );
  134.  
  135.             if(( IE->C_Prefs & CLICKED ) && (!( item->min_NumSubs )) && (!( item->min_Flags & M_BARLABEL ))) {
  136.             TEXT    Label[60];
  137.  
  138.             StrToLower( item->min_Label, Label );
  139.  
  140.             FPrintf( Files->Std, "{%smenued}", Label );
  141.  
  142.             if( IE->C_Prefs & GEN_TEMPLATE )
  143.                 FPrintf( Files->Temp, MenuTmp, Label, buffer );
  144.  
  145.             } else {
  146.             FPuts( Files->Std, Null );
  147.             }
  148.  
  149.             FPuts( Files->Std, ",\n" );
  150.  
  151.             strcat( buffer, "/" );
  152.  
  153.             for( sub = item->min_Subs.mlh_Head; sub->msn_Node.ln_Succ; sub = sub->msn_Node.ln_Succ ) {
  154.  
  155.             lens = strlen( sub->msn_Text );
  156.             strcat( buffer, sub->msn_Text );
  157.  
  158.             str = sub->msn_Image ? "\t    IM_SUB" : "\t    NM_SUB";
  159.             FPuts( Files->Std, str );
  160.  
  161.             FPuts( Files->Std, ", " );
  162.  
  163.             if( sub->msn_Flags & M_BARLABEL ) {
  164.                 FPuts( Files->Std, "NM_BARLABEL" );
  165.             } else {
  166.                 if( img = sub->msn_Image ) {
  167.                 TEXT    Label[60];
  168.  
  169.                 (ULONG)img -= sizeof( struct Node );
  170.  
  171.                 StrToLower( img->in_Label, Label );
  172.                 FPrintf( Files->Std, "{%simg}", Label );
  173.                 } else {
  174.                 if( sub->msn_Text[0] )
  175.                     if( smart )
  176.                     FPrintf( Files->Std, "%s", (FindString( &Files->Strings, sub->msn_Text ))->Label );
  177.                     else
  178.                     FPrintf( Files->Std, "'%s'", sub->msn_Text );
  179.                 else
  180.                     FPuts( Files->Std, Null );
  181.                 }
  182.             }
  183.  
  184.             FPuts( Files->Std, ", " );
  185.  
  186.             if( sub->msn_CommKey[0] ) {
  187.                 if( smart )
  188.                 FPrintf( Files->Std, "%s", (FindString( &Files->Strings, sub->msn_CommKey ))->Label );
  189.                 else
  190.                 FPrintf( Files->Std, "'%s'", sub->msn_CommKey );
  191.             } else
  192.                 FPuts( Files->Std, Null );
  193.  
  194.             FPrintf( Files->Std, ", $%lx, %ld, ", sub->msn_Flags, sub->msn_MutualExclude );
  195.  
  196.             if(( IE->C_Prefs & CLICKED ) && (!( sub->msn_Flags & M_BARLABEL ))) {
  197.                 TEXT    Label[60];
  198.  
  199.                 StrToLower( sub->msn_Label, Label );
  200.  
  201.                 FPrintf( Files->Std, "{%smenued}", Label );
  202.  
  203.                 if( IE->C_Prefs & GEN_TEMPLATE )
  204.                 FPrintf( Files->Temp, MenuTmp, Label, buffer );
  205.  
  206.             } else {
  207.                 FPuts( Files->Std, Null );
  208.             }
  209.  
  210.             FPuts( Files->Std, ",\n" );
  211.  
  212.             buffer[ lent+leni+2 ] = '\0';
  213.             }
  214.  
  215.             buffer[ lent+1 ] = '\0';
  216.         }
  217.         }
  218.  
  219.         FPuts( Files->Std, "\tNM_END, NIL, NIL, 0, 0, NIL ]:newmenu\n" );
  220.     }
  221.     }
  222. }
  223. ///
  224. /// WriteITexts
  225. void WriteITexts( struct GenFiles *Files, struct IE_Data *IE )
  226. {
  227.     struct WindowInfo  *wnd;
  228.     struct ITextNode   *txt;
  229.     struct TxtAttrNode *fnt;
  230.     UWORD               x, y, next;
  231.     ULONG               loc;
  232.  
  233.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  234.     if( wnd->wi_NumTexts ) {
  235.         TEXT    Label[60];
  236.  
  237.         StrToLower( wnd->wi_Label, Label );
  238.  
  239.         loc = IE->C_Prefs & SMART_STR;
  240.  
  241.         if( IE->SrcFlags & LOCALIZE )
  242.         loc = wnd->wi_Tags & W_LOC_TEXTS;
  243.  
  244.         FPrintf( Files->Std, "\nDEF %sitext = [\n", Label );
  245.  
  246.         next = 1;
  247.  
  248.         for( txt = wnd->wi_ITexts.mlh_Head; txt->itn_Node.ln_Succ; txt = txt->itn_Node.ln_Succ ) {
  249.  
  250.         FPrintf( Files->Std, "\t%ld, %ld, %ld, ",
  251.              txt->itn_FrontPen, txt->itn_BackPen, txt->itn_DrawMode );
  252.  
  253.         x = txt->itn_LeftEdge - IE->ScreenData->XOffset;
  254.         y = txt->itn_TopEdge - IE->ScreenData->YOffset;
  255.  
  256.         if( IE->SrcFlags & FONTSENSITIVE ) {
  257.             x += ( IntuiTextLength(( struct IntuiText * )&txt->itn_FrontPen ) >> 1 );
  258.             y += ( IE->ScreenData->Screen->RastPort.TxHeight >> 1 );
  259.         }
  260.  
  261.         FPrintf( Files->Std, "%ld, %ld, ", x, y );
  262.  
  263.         if( fnt = txt->itn_ITextFont ) {
  264.             TEXT    Label[30];
  265.  
  266.             (ULONG)fnt -= sizeof( struct Node );
  267.  
  268.             StrToLower( fnt->txa_Label, Label );
  269.             FPrintf( Files->Std, "{%s}", Label );
  270.         } else {
  271.             FPuts( Files->Std, Null );
  272.         }
  273.  
  274.         FPuts( Files->Std, ", " );
  275.  
  276.         if( loc )
  277.             FPrintf( Files->Std, "%s", (FindString( &Files->Strings, txt->itn_Text ))->Label );
  278.         else
  279.             FPrintf( Files->Std, "'%s'", txt->itn_Text );
  280.  
  281.         if((!( IE->SrcFlags & FONTSENSITIVE )) && ( next != wnd->wi_NumTexts )) {
  282.             FPrintf( Files->Std, ", {%sitext[%ld]},\n", Label, next );
  283.             next += 1;
  284.         } else {
  285.             FPuts( Files->Std, ", NIL,\n" );
  286.         }
  287.         }
  288.  
  289.         Flush( Files->Std );
  290.         Seek( Files->Std, -2, OFFSET_CURRENT );
  291.         FPuts( Files->Std, "\n]:intuitext\n" );
  292.  
  293.     }
  294.     }
  295. }
  296. ///
  297. /// WriteImgStruct
  298. void WriteImgStruct( struct GenFiles *Files, struct IE_Data *IE )
  299. {
  300.     struct ImageNode   *img;
  301.  
  302.     for( img = IE->Img_List.mlh_Head; img->in_Node.ln_Succ; img = img->in_Node.ln_Succ ) {
  303.  
  304.     FPrintf( Files->Std, "\nstruct Image %sImg = {\n", img->in_Label );
  305.  
  306.     VFPrintf( Files->Std, "\t%d, %d,\n\t%d, %d, %d,\n\t", &img->in_Left );
  307.  
  308.     if( img->in_Size )
  309.         FPrintf( Files->Std, "%sImgData", img->in_Label );
  310.     else
  311.         FPuts( Files->Std, Null );
  312.  
  313.     FPrintf( Files->Std, ",\n\t%ld, %ld,\n\t0\n};\n",
  314.          img->in_PlanePick, img->in_PlaneOnOff );
  315.     }
  316. }
  317. ///
  318. /// WriteImageStruct
  319. void WriteImageStruct( struct GenFiles *Files, struct IE_Data *IE )
  320. {
  321.     struct WindowInfo  *wnd;
  322.     struct WndImages   *img;
  323.     UWORD               cnt;
  324.  
  325.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  326.  
  327.     cnt = 0;
  328.  
  329.     for( img = wnd->wi_Images.mlh_Head; img->wim_Next; img = img->wim_Next ) {
  330.  
  331.         FPrintf( Files->XDef, "extern struct Image\t\t%s_%ldImage;\n", wnd->wi_Label, cnt );
  332.         FPrintf( Files->Std, "\nstruct Image %s_%ldImage = {\n", wnd->wi_Label, cnt );
  333.  
  334.         cnt += 1;
  335.  
  336.         FPrintf( Files->Std, "\t%ld, %ld,\n\t%ld, %ld, %ld,\n\t",
  337.              img->wim_Left - IE->ScreenData->XOffset,
  338.              img->wim_Top  - IE->ScreenData->YOffset,
  339.              img->wim_Width, img->wim_Height, img->wim_Depth );
  340.  
  341.         if( img->wim_ImageNode->in_Size )
  342.         FPrintf( Files->Std, "%sImgData", img->wim_ImageNode->in_Label );
  343.         else
  344.         FPuts( Files->Std, Null );
  345.  
  346.         FPrintf( Files->Std, ",\n\t%ld, %ld,\n\t",
  347.              img->wim_PlanePick, img->wim_PlaneOnOff );
  348.  
  349.         if( cnt < wnd->wi_NumImages )
  350.         FPrintf( Files->Std, "&%s_%ldImage", wnd->wi_Label, cnt );
  351.         else
  352.         FPuts( Files->Std, Null );
  353.  
  354.         FPuts( Files->Std, "\n};\n" );
  355.     }
  356.     }
  357. }
  358. ///
  359.  
  360.